package com.nt.oam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.nt.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.nt.common.annotation.Log;
import com.nt.common.core.controller.BaseController;
import com.nt.common.core.domain.AjaxResult;
import com.nt.common.enums.BusinessType;
import com.nt.oam.domain.AntPersonnelManage;
import com.nt.oam.service.IAntPersonnelManageService;
import com.nt.common.utils.poi.ExcelUtil;
import com.nt.common.core.page.TableDataInfo;

/**
 * 人员管理Controller
 *
 * @author JZFeng
 * @date 2025-02-05
 */
@RestController
@RequestMapping("/oam/manage" )
public class AntPersonnelManageController extends BaseController {
    @Autowired
    private IAntPersonnelManageService antPersonnelManageService;

    /**
     * 查询人员管理列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:manage:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(AntPersonnelManage antPersonnelManage) {
        startPage();
        List<AntPersonnelManage> list = antPersonnelManageService.selectAntPersonnelManageList(antPersonnelManage);
        return getDataTable(list);
    }

    /**
     * 导出人员管理列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:manage:export')" )
    @Log(title = "人员管理" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, AntPersonnelManage antPersonnelManage) {
        List<AntPersonnelManage> list = antPersonnelManageService.selectAntPersonnelManageList(antPersonnelManage);
        ExcelUtil<AntPersonnelManage> util = new ExcelUtil<AntPersonnelManage>(AntPersonnelManage.class);
        util.exportExcel(response, list, "人员管理数据" );
    }

    /**
     * 获取人员管理详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:manage:query')" )
    @GetMapping(value = "/{personId}" )
    public AjaxResult getInfo(@PathVariable("personId" ) Long personId) {
        return success(antPersonnelManageService.selectAntPersonnelManageByPersonId(personId));
    }

    /**
     * 新增人员管理
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:manage:add')" )
    @Log(title = "人员管理" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AntPersonnelManage antPersonnelManage) {
        return toAjax(antPersonnelManageService.insertAntPersonnelManage(antPersonnelManage));
    }

    /**
     * 修改人员管理
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:manage:edit')" )
    @Log(title = "人员管理" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AntPersonnelManage antPersonnelManage) {
        return toAjax(antPersonnelManageService.updateAntPersonnelManage(antPersonnelManage));
    }

    /**
     * 删除人员管理
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:manage:remove')" )
    @Log(title = "人员管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{personIds}" )
    public AjaxResult remove(@PathVariable Long[] personIds) {
        return toAjax(antPersonnelManageService.deleteAntPersonnelManageByPersonIds(personIds));
    }

    /**
     * 获取页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:manage:query')")
    @GetMapping(value = "/get/isModify")
    public AjaxResult getManageModify(@RequestParam Long personId) {
        return success(antPersonnelManageService.selectPersonModify(personId));
    }

    /**
     * 修改页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:manage:edit')")
    @Log(title = "人员管理", businessType = BusinessType.UPDATE)
    @PostMapping("edit/modify/{personId}")
    public AjaxResult editModify(@PathVariable("personId") Long personId) {
        int isModify = 1;
        return toAjax(antPersonnelManageService.updatePersonModify(personId,isModify));
    }
}
